class_name 毒攻击 extends Ability

func _init() -> void:
	#self.has_effect.append(Hurt)
	self.has_effect.append(Poison)

func activate_ability(_as:AbilitySystem = AS) -> void:
	攻击()
	self.touch_ability.emit()
	pass
# 结束技能

func 获取敌人():
	var drs = self.AS.get_tree().get_nodes_in_group("敌人")
	if drs.size() > 0:
		var rand_id = randi_range(0,drs.size()-1)
		return drs[rand_id]
	return null

func 攻击():
	var target = 获取敌人()
	if target:
		var flyball = preload("res://塔防/飞球特效/flyball.tscn").instantiate()
		self.AS.get_parent().add_child(flyball)
		flyball.setTarget(target)
		flyball.hit.connect(_on_flyball_hit)

# 来自飞球的命中信号
func _on_flyball_hit(_target):
	if _target != null:
		if _target as 敌人:
			# 如果命中敌人，就在敌人身上的ability_system中加入“造成伤害”的effect
			commit_effect(_target.get_AbilitySystem())
	pass
